import unittest
from selenium import selenium
from time import sleep

class SeleniumTest(unittest.TestCase):
    def setUp(self):
        self.selenium = selenium("localhost", \
            4444, "*firefox", "http://localhost:8080")
        self.selenium.start()


    def login_as_admin(self):
        sel = self.selenium
        sel.open("/")
        sel.wait_for_page_to_load("30000")
        sel.click("link=Login")
        sel.wait_for_page_to_load("30000")
        sel.click("admin")
        sel.click("submit-login")
        sel.wait_for_page_to_load("30000")

    ## Create questions
    def create_question(self, question, alt0, alt1, alt2, alt3, correct):
        sel = self.selenium
        sel.open("/questions_browse")
        sel.wait_for_page_to_load("30000")
        sel.click("link=Create New Question")
        sel.wait_for_page_to_load("30000")
        sel.type("question", question)
        sel.type("alt0", alt0)
        sel.type("alt1", alt1)
        sel.type("alt2", alt2)
        sel.type("alt3", alt3)
        sel.type("correct", correct)
        sel.click("Save")
        
    def test_all(self):
        self.login_as_admin()
        sel = self.selenium
        self.create_question(
                        "Which American president was killed in Texas?",
                        "Obama", "Michel Jackson", "Oprah", "Caterine Keyl",
                        "0")
         
        self.create_question(
                        "The sum of 3 and 4 is?",
                        "8", "7", "6", "5",
                        "1")
                        
        self.create_question(
                        "In which part of the world lives the gnu?",
                        "All", "Some", "None", "Linux",
                        "3")
 
        
    def tearDown(self):
        self.selenium.stop()

if __name__ == "__main__":
    unittest.main()


